import java.io.*;
import java.util.HashMap;
public class t7  {
    public static void main(String args[])throws IOException {
        analyse7();
    }
    private static void analyse7() throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\Users\\gdq\\OneDrive\\桌面\\File文件夹\\jobs_new.txt")));

        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:\\Users\\gdq\\OneDrive\\桌面\\File文件夹\\res.txt")));

        HashMap<String,Double> WorkCity = new HashMap<>();
        String line ;
        while (((line=bufferedReader.readLine())!=null)){
            String[] arr = line.split(",");
            String workage = arr[3];
            double avg = 0;
            if(arr[4].contains("-")){
                String[] salary = arr[4].split("-");
                double low = Double.parseDouble(salary[0]);
                String sal = salary[1];
                if(sal.contains("元")){
                    double high = Double.parseDouble(sal.split("元")[0]);
                    avg = (low+high)/2;
                }else if (sal.contains("k")){
                    double high = Double.parseDouble(sal.split("k")[0]);
                    high = high*1000;
                    avg = (low*1000+high)/2;
                }else if (sal.contains("万")){
                    double high = Double.parseDouble(sal.split("万")[0]);
                    high = high*10000;
                    avg = (low*10000+high)/2;
                }else {
                    double high = Double.parseDouble(salary[1]);
                    avg = (low+high)/2;
                }
            }else {
                avg = Double.parseDouble(arr[4]);
            }

            WorkCity.put(workage, WorkCity.containsKey(workage)?(WorkCity.get(workage)+avg)/2:avg);
        }

        for (String key:WorkCity.keySet()){
            bufferedWriter.write("=================================================================");
            bufferedWriter.newLine();
            bufferedWriter.write("工作学历为"+key+"的平均薪资为:");
            bufferedWriter.newLine();
            bufferedWriter.write(String.valueOf(WorkCity.get(key)));

        }
        bufferedWriter.flush();
        bufferedReader.close();
        bufferedWriter.close();
    }

}
